Skip to content

Comments

fix: implement device auth nonce challenge-response flow#35

Open
othreecodes wants to merge 1 commit intoibelick:mainfrom
othreecodes:fix/device-auth-nonce
Open

fix: implement device auth nonce challenge-response flow#35
othreecodes wants to merge 1 commit intoibelick:mainfrom
othreecodes:fix/device-auth-nonce

Conversation

@othreecodes
Copy link

Problem

WebClaw fails to connect to OpenClaw gateways that enforce device authentication with the nonce challenge-response protocol, returning device nonce required (WebSocket close code 1008).

Cause

gateway.ts sent the connect request immediately after WebSocket open without waiting for the connect.challenge event from the gateway. The nonce was never included in the device signature, so the gateway rejected the handshake.

Fix

  • Added waitForConnectChallenge() function that listens for the connect.challenge event and extracts the nonce
  • Updated buildConnectParams() to accept an optional nonce parameter
  • When a nonce is present, the signature uses v2 payload format (which includes the nonce in the signed data)
  • Updated all four connection entry points: connectGateway, createGatewayClient.connect, gatewayRpc, and gatewayConnectCheck

How It Works

  1. Client opens WebSocket to the gateway
  2. Gateway sends connect.challenge event with a nonce
  3. Client signs the nonce into the device auth payload (v2 format)
  4. Client sends connect request with the signed nonce
  5. Gateway verifies and accepts the connection

Backward compatible: falls back to v1 format if no nonce is provided.

The gateway requires a two-step device authentication handshake:
1. After WebSocket open, the gateway sends a connect.challenge event with a nonce
2. The client must include this nonce in the device signature (using v2 payload format)

Previously, gateway.ts sent the connect request immediately without waiting
for the challenge event, causing "device nonce required" (code 1008) errors
on gateways that enforce device auth.

Changes:
- Add waitForConnectChallenge() to listen for the connect.challenge event
- Update buildConnectParams() to accept optional nonce parameter
- Use v2 signature format (includes nonce) when nonce is present
- Update all four connection points: connectGateway, createGatewayClient,
  gatewayRpc, and gatewayConnectCheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant